package com.db4o.odbgen.plugins.java.maingenerator.typedxmlschema.xtree;

import com.db4o.odbgen.OdbgenException;
import com.db4o.odbgen.plugins.java.maingenerator.typedxmlschema.TSField;

/**
 * A XTree element representing a field.
 * @author liviug
 *
 */

public class XTEField extends XTreeElement {
	private TSField _field;
	
	public XTEField(){
		super();
	}

	public void setField(TSField field) {
		this._field = field;
	}

	public TSField getField() {
		return _field;
	}
	
	/**
	 * Returns the only child of this field if any.
	 * The child may be a class or an enumeration. 
	 * @throws OdbgenException 
	 */
	public XTreeElement getChild() throws OdbgenException{
		if(this.getChildren().size()==0){
			return null;
		}
		if(this.getChildren().size()==1){
			return this.getChildren().get(0);
		}
		else{
			throw new OdbgenException("The field '%s' has more than one child.", this.getField().getName());
		}
	}
}
